<?php

//入库查询
class GetStoreApp extends MallbaseApp
{


    function index()
    {
        $data = array();
        $RKCode = empty($_REQUEST['RKCode']) ? '' : trim($_REQUEST['RKCode']);
        $HZunit = empty($_REQUEST['HZunit']) ? '' : trim($_REQUEST['HZunit']);
        $pageIndex = empty($_REQUEST['pageIndex']) ? 1 : trim($_REQUEST['pageIndex']);
        $Godown = empty($_REQUEST['Godown']) ? '' : trim($_REQUEST['Godown']);
        //$wxNum = empty($_REQUEST['wxNum']) ? '123' : trim($_REQUEST['wxNum']);
        $wxNum = isset($_COOKIE['wxid'])?$_COOKIE['wxid']:'';
        if(empty($wxNum)){
            echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
            echo "<script>alert('授权未成功');  window.location.href='http://dskc.csrsfwl.com/index.php?app=login'; </script>  ";//使用weixin.php的页面
        }
        if ($this->checkUrl(WEB_SERVICE2)) {
            $client = new soapclient(WEB_SERVICE2);
            $client->soap_defencoding = 'utf-8';
            $client->decode_utf8 = false;
            $client->xml_encoding = 'utf-8';
            $param = array(
                'pjson' => '{"pageIndex":"' . $pageIndex . '","RKCode":"' . $RKCode . '","HZunit":"' . $HZunit . '","Godown":"' . $Godown . '","wxNum": "' . $wxNum . '"}');
//            echo $param['pjson'];
            $result = $client->__Call("GetStore", array($param));
            if (is_soap_fault($result)) {
                trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
            } else {
                $result = json_decode(json_encode($result->GetStoreResult), TRUE);
                $result = preg_replace('/([\r\n])/', '', $result);
                $result = json_decode($result, true);
                if ($result['status'] == 1) {
                    $data = $result['result'];
                    $dataCount = $result['dataCount'];
                } else {
                    if ($result['result'] == '该用户未登录') {
                        echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
                        echo "<script>alert('请先绑定微信'); window.location.href='index.php?app=login&hist=getstore&wxNum=".$wxNum."'; </script>  ";
                        exit();
                    } elseif (strstr($result['result'], '该用户无权')) {
                        echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
                        echo "<script>alert('$result[result]'); window.location.href='index.php?app=menu'; </script>  ";
                        exit();
                    } else {
                        echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
                        echo "<script>alert('$result[result]');</script>  ";
                    }
                }

            }
        }
        $this->import_resource(array('script' => 'jquery.ui/jquery.ui.js,jquery.ui/i18n/' . i18n_code() . '.js',
            'style' => 'jquery.ui/themes/ui-lightness/jquery.ui.css'));
        if ($data) {
            $this->assign('getstores', $data);
            $page = $this->_get_page();
            $page['item_count'] = $dataCount;
            $this->_format_pageweb($page);
            $this->assign('page_info', $page);
        }
        $this->display('getstore.index.html');
    }

    //明细
    function detail()
    {
        $key = isset($_REQUEST['id']) ? trim($_REQUEST['id']) : '';
        $data = array();
        //$wxNum = empty($_REQUEST['wxNum']) ? '123' : trim($_REQUEST['wxNum']);
        $pageIndex = empty($_REQUEST['pageIndex']) ? 1 : trim($_REQUEST['pageIndex']);
        $wxNum = isset($_COOKIE['wxid'])?$_COOKIE['wxid']:'';
        if(empty($wxNum)){
            echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
            echo "<script>alert('授权未成功');  window.location.href='http://dskc.csrsfwl.com/index.php?app=login'; </script>  ";//使用weixin.php的页面
        }
        if ($this->checkUrl(WEB_SERVICE2)) {
            $client = new soapclient(WEB_SERVICE2);
            $client->soap_defencoding = 'utf-8';
            $client->decode_utf8 = false;
            $client->xml_encoding = 'utf-8';
            $param = array(
                'pjson' => '{"pageIndex":"' . $pageIndex . '","key":"' . $key . '","wxNum": "' . $wxNum . '"}');
            $result = $client->__Call("GetStoreMX", array($param));
            if (is_soap_fault($result)) {
                trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
            } else {
                $result = json_decode(json_encode($result->GetStoreMXResult), TRUE);
                $result = json_decode($result, true);
                if ($result['status'] == 1) {
                    $data = $result['result'];


                }

            }
        }

        if ($data) {
            $this->assign('getstores', $data);
        }
        $this->display('getstore.detail.html');
    }

    //列表更多
    function listmore()
    {
        $SIM_TId = isset($_REQUEST['id']) ? trim($_REQUEST['id']) : '';
        $data = array();
        $pageIndex = empty($_REQUEST['pageIndex']) ? 1 : trim($_REQUEST['pageIndex']);
        $RKCode = empty($_REQUEST['RKCode']) ? '' : trim($_REQUEST['RKCode']);
        $HZunit = empty($_REQUEST['HZunit']) ? '' : trim($_REQUEST['HZunit']);
        $Godown = empty($_REQUEST['Godown']) ? '' : trim($_REQUEST['Godown']);
        //$wxNum = empty($_REQUEST['wxNum']) ? '123' : trim($_REQUEST['wxNum']);
        $wxNum = isset($_COOKIE['wxid'])?$_COOKIE['wxid']:'';
        if(empty($wxNum)){
            echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
            echo "<script>alert('授权未成功');  window.location.href='http://dskc.csrsfwl.com/index.php?app=login'; </script>  ";//使用weixin.php的页面
        }
        if ($this->checkUrl(WEB_SERVICE2)) {
            $client = new soapclient(WEB_SERVICE2);
            $client->soap_defencoding = 'utf-8';
            $client->decode_utf8 = false;
            $client->xml_encoding = 'utf-8';
            $param = array(
                'pjson' => '{"pageIndex":"' . $pageIndex . '","RKCode":"' . $RKCode . '","HZunit":"' . $HZunit . '","Godown":"' . $Godown . '","wxNum": "' . $wxNum . '"}');
            $result = $client->__Call("GetStore", array($param));
            if (is_soap_fault($result)) {
                trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
            } else {
                $result = json_decode(json_encode($result->GetStoreResult), TRUE);
                $result = json_decode($result, true);

                if ($result['status'] == 1) {
                    foreach ($result['result'] as $key => $val) {
                        if ($val['SIM_TId'] == $SIM_TId) {
                            $data = $val;
                            break;
                        }
                    }
                } else {
                    /*  echo $result['result'];*/

                }


            }
        }
        if ($data) {
            $this->assign('getstore', $data);
        }
        $this->display('getstore.listmore.html');
    }

    //明细更多
    function infomore()
    {
        $key = isset($_REQUEST['id']) ? trim($_REQUEST['id']) : '';
        $SIS_Tid = isset($_REQUEST['tid']) ? trim($_REQUEST['tid']) : '';
        $data = array();
        $pageIndex = empty($_REQUEST['pageIndex']) ? 1 : trim($_REQUEST['pageIndex']);
        $RKCode = empty($_REQUEST['RKCode']) ? '' : trim($_REQUEST['RKCode']);
        $HZunit = empty($_REQUEST['HZunit']) ? '' : trim($_REQUEST['HZunit']);
        $Godown = empty($_REQUEST['Godown']) ? '' : trim($_REQUEST['Godown']);
        //$wxNum = empty($_REQUEST['wxNum']) ? '123' : trim($_REQUEST['wxNum']);
        $wxNum = isset($_COOKIE['wxid'])?$_COOKIE['wxid']:'';
        if(empty($wxNum)){
            echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
            echo "<script>alert('授权未成功');  window.location.href='http://dskc.csrsfwl.com/index.php?app=login'; </script>  ";//使用weixin.php的页面
        }
        if ($this->checkUrl(WEB_SERVICE2)) {
            $client = new soapclient(WEB_SERVICE2);
            $client->soap_defencoding = 'utf-8';
            $client->decode_utf8 = false;
            $client->xml_encoding = 'utf-8';
            $param = array(
                'pjson' => '{"pageIndex":"' . $pageIndex . '","key":"' . $key . '","RKCode":"' . $RKCode . '","HZunit":"' . $HZunit . '","Godown":"' . $Godown . '","wxNum": "' . $wxNum . '"}');
            $result = $client->__Call("GetStoreMX", array($param));
            if (is_soap_fault($result)) {
                trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
            } else {
                $result = json_decode(json_encode($result->GetStoreMXResult), TRUE);
                $result = json_decode($result, true);
                if ($result['status'] == 1) {
                    foreach ($result['result'] as $k => $val) {
                        if ($val['SIS_Tid'] == $SIS_Tid) {
                            $data = $val;
                            break;
                        }
                    }
                } else {
                    /*  echo $result['result'];*/

                }


            }
        }
        if ($data) {
            $this->assign('getstore', $data);
        }
        $this->display('getstore.infomore.html');
    }

}
